import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import {axios} from "@/utils/axios"
import {data} from "./data"

export default new Vuex.Store({
  modules:{
     data:data
  },

  state: {  // 对象 存储所有组件的数据 
    userinfo:null,
    count:1,
    xuekeList:[],
    categories:[],
    banjiList:[],
    counter:2002,
    city:"美丽的大冶...",
    word:"wh2002-daydayup",
    obj:{
      list:null,
      money:2000,
      mv:[]
    }
  }, 
  getters:{
    newCount(state){
      return state.counter / 8;
    }
  },
  mutations: {   // 修改 state 数据
    changeuesrinfo(state,payload){
      state.userinfo = payload;
    },
    changexuekeList(state,payload){
      state.xuekeList = payload;
    },
    changecategories(state,payload){
      state.categories = payload;
    },
    changebanjiList(state,payload){
      state.banjiList = payload;
    },
    changeCounter(state,payload){
      state.counter += payload;
    },
    changeCity(state,payload){
      state.city = payload;
    },
    changeWord(state,payload){
      state.word = payload;
    },
    changeObjMoney(state,payload){
      // state.obj.money = payload;
      state.obj = {...state.obj,money:payload}
    },
    changeList(state,payload){
      state.obj = {...state.obj,list:payload}
    },
    changeMv(state,payload){
      state.obj = {...state.obj,mv:payload}
    }
   
  },
  actions: {
      changeListAc( context,payload ){   // context  == {commit:function(){}} = {commit:commit} = {commit}
         context.commit("changeList",payload);
      },
      changeMvAc({commit}){  //  {commit:commit}
        axios.post("/vue/getpronamelist")
        .then(res=>{
          if(res.data.type){
            commit("changeMv",res.data.result);
          }
        })
      }
  },
  
})
